<?

// forum index component 

if( !$PARAPARA )
    die("Do not call me");

$dbl    = $PARAPARA->dblayer;

$options = array( 'compact' => true );

echo "<div id=\"para_forum_container\">\n";
echo "<div id=\"para_forum_caption\">Debatten</div>\n";
echo "<div id=\"para_forum_console\">\n";

// thread view ..................................................
if( is_numeric($_GET['tview']) ) {

    $thread_id = $_GET['tview'];
    $thread    = $PARAPARA->get_thread( $thread_id );

    $bodies    = null;
    if( is_array($_GET['b']) ) {
        $body_ids = array();
        foreach( $_GET['b'] as $id ) {
            if( is_numeric( $id )) {
                array_push( $body_ids, $id );
            }
        }
        $bodies = $dbl->get_forum_message_bodies( $body_ids );        
        $thread->add_bodies( $bodies );

        //echo "<pre>", var_dump( $thread ), "</pre>";
        //return;
    }
    if($thread) {
        $thread->htmlize( array('expanded' => true, 
                                'bodies' => $body_ids )
            );

    }
    else {
        echo "<div>Not found $dbl->latest_error</div>";
    }
}

// full view ..................................................
else {
    $forum  = $PARAPARA->get_forum( '*' );
    $forum->htmlize( $options );
}

echo "</div>\n";
echo "</div>\n";

?>
